﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace ParticleEditor
{
    public struct Particles
    {
        public float m_fX;
        public float m_fY;
        public float m_fVelX_VOT;
        public float m_fVelX_End;
        public float m_fVelX_Current;
        public float m_fVelY_VOT;
        public float m_fVelY_End;
        public float m_fVelY_Current;
        public float m_fLife_Current;
        public float m_fScaleX_Current;
        public float m_fScaleY_Current;
        public float m_fScaleX_End;
        public float m_fScaleY_End;
        public float m_fScaleX_SOT;
        public float m_fScaleY_SOT;
        public float m_fRotation_Current;
        public float m_fRotation_End;
        public float m_fRotation_ROT;
        public float m_fColorR_Current;
        public float m_fColorR_End;
        public float m_fColorG_Current;
        public float m_fColorG_End;
        public float m_fColorB_Current;
        public float m_fColorB_End;
        public float m_fColorA_Current;
        public float m_fColorA_End;
        public float m_fColorR_COT;
        public float m_fColorG_COT;
        public float m_fColorB_COT;
        public float m_fColorA_COT;
        public int m_nImageID;

    }
    public class Emitter
    {
        public List<Particles> listed = new List<Particles>();
        public List<Particles> delisted = new List<Particles>();
        public int m_nPosX;
        public int m_nPosY;
        public int m_nH;
        public int m_nW;
        public int m_nRTop;
        public int m_nRBottom;
        public int m_nRLeft;
        public int m_nRRight;

        public float m_fSpawnRate;
        public float m_fScaleX_Start;
        public float m_fScaleX_End;
        public float m_fScaleY_Start;
        public float m_fScaleY_End;
        public float m_fColorR_Start;
        public float m_fColorR_End;
        public float m_fColorG_Start;
        public float m_fColorG_End;
        public float m_fColorB_Start;
        public float m_fColorB_End;
        public float m_fColorA_Start;
        public float m_fColorA_End;
        public float m_fVelXS;
        public float m_fVelXS2;
        public float m_fVelXE;
        public float m_fVelXE2;
        public float m_fVelYS;
        public float m_fVelYS2;
        public float m_fVelYE;
        public float m_fVelYE2;
        public float m_fRotation_Start;
        public float m_fRotation_End;
        public string m_strName;
        public bool m_bLooping;
        public int m_nImageIDs;
        public int m_nLife_Max;
        public int m_nLife_Min;
        public int m_nMaxParticles;
        public int m_nSourceBlend;
        public int m_nDestBlend;
        public int m_nImageX;
        public int m_nImageY;

        public Particles Generate()
        {
            byte[] rando = new byte[20];
            int[] bob = new int[20];
            RandomNumberGenerator numberGenerator = System.Security.Cryptography.RandomNumberGenerator.Create();
            numberGenerator.GetNonZeroBytes(rando);
            for (int q = 0; q < 20; q++)
            {
                bob[q] = rando[q];
            }


            int vsx = (int)(m_fVelXS); int vsx2 = (int)(m_fVelXS2);
            int vex = (int)(m_fVelXE); int vex2 = (int)(m_fVelXE2);
            int vsy = (int)(m_fVelYS); int vsy2 = (int)(m_fVelYS2);
            int vey = (int)(m_fVelYE); int vey2 = (int)(m_fVelYE2);

            Particles temps = new Particles();

            temps.m_fX = m_nPosX;
            temps.m_fY = m_nPosY;

            temps.m_fLife_Current = new Random(bob[0]).Next(m_nLife_Min, m_nLife_Max); 
            temps.m_fVelX_End = new Random(bob[1]).Next(vex2, vex);
            temps.m_fVelX_Current = new Random(bob[2]).Next(vsx2, vsx);
            temps.m_fVelY_End = new Random(bob[3]).Next(vey2, vey);
            temps.m_fVelY_Current = new Random(bob[4]).Next(vsy2, vsy);
            temps.m_fVelX_VOT = (m_fVelXE - m_fVelXS) / temps.m_fLife_Current;
            temps.m_fVelY_VOT = (m_fVelYE - m_fVelYS) / temps.m_fLife_Current;
            temps.m_fScaleX_Current = m_fScaleX_Start;
            temps.m_fScaleY_Current = m_fScaleY_Start;
            temps.m_fScaleX_End = m_fScaleX_End;
            temps.m_fScaleY_End = m_fScaleY_End;
            temps.m_fScaleX_SOT = (m_fScaleX_End - m_fScaleX_Start) / m_nLife_Max;
            temps.m_fScaleY_SOT = (m_fScaleY_End - m_fScaleY_Start) / m_nLife_Max;
            temps.m_fRotation_Current = m_fRotation_Start;
            temps.m_fRotation_End = m_fRotation_End;
            temps.m_fRotation_ROT = (m_fRotation_End - m_fRotation_Start) / m_nLife_Max;
            temps.m_fColorR_Current = m_fColorR_Start;
            temps.m_fColorR_End = m_fColorR_End;
            temps.m_fColorG_Current = m_fColorG_Start;
            temps.m_fColorG_End = m_fColorG_End;
            temps.m_fColorB_Current = m_fColorB_Start;
            temps.m_fColorB_End = m_fColorB_End;
            temps.m_fColorA_Current = m_fColorA_Start;
            temps.m_fColorA_End = m_fColorA_End;
            temps.m_fColorR_COT = (m_fColorR_End - m_fColorR_Start) / m_nLife_Max;
            temps.m_fColorG_COT = (m_fColorG_End - m_fColorG_Start) / m_nLife_Max;
            temps.m_fColorB_COT = (m_fColorB_End - m_fColorB_Start) / m_nLife_Max;
            temps.m_fColorA_COT = (m_fColorA_End - m_fColorA_Start) / m_nLife_Max;


            return temps;
        }

        public void Starts()
        {
            m_nPosX = 2;
            m_nPosY = 2;
            m_fSpawnRate = 0.25f;
            m_fScaleX_Start = 1;
            m_fScaleX_End = 1;
            m_fScaleY_Start = 1;
            m_fScaleY_End = 1;
            m_fColorR_Start = 1;
            m_fColorR_End = 255;
            m_fColorG_Start = 1;
            m_fColorG_End = 255;
            m_fColorB_Start = 1;
            m_fColorB_End = 255;
            m_fColorA_Start = 200;
            m_fColorA_End = 255;
            m_fVelXS = 10;
            m_fVelXS2 = -10;
            m_fVelXE = 20;
            m_fVelXE2 = -20;
            m_fVelYS = 10;
            m_fVelYS2 = -10;
            m_fVelYE = 20;
            m_fVelYE2 = -20;
            m_fRotation_Start = 0;
            m_fRotation_End = 1;
            // this.TheOne.m_strName         
            m_bLooping = true;
            m_nLife_Max = 10;
            m_nLife_Min = 1;
            m_nMaxParticles = 10;
            m_nSourceBlend = 2;
            m_nDestBlend = 2;
            m_nImageX = 64;
            m_nImageY = 64;
            m_nH = 100;
            m_nW = 100;
            m_nRTop = 50;
            m_nRBottom = 150;
            m_nRLeft = 50;
            m_nRRight = 150;
            listed.Capacity.Equals(100);
            for (int i = 0; i < m_nMaxParticles; i++)
            {
                listed.Add(Generate());
            }



        }


    

    }

}
